<template>
  <div class="app-container">
    <el-drawer title="审核" :visible.sync="showFlag" size="60%" :append-to-body="true">
      <template v-slot:title>
        <span class="titleDiv">审核</span>
      </template>
      <div style="padding: 0 20px;">
        <el-form ref="formCheck" :model="form" :rules="rules" label-width="auto">
          <el-form-item label="审核结果:" prop="examineResult">
            <el-radio-group v-model="form.examineResult">
              <el-radio label="1" border>合格</el-radio>
              <el-radio label="0" border>不合格</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="审核原因:" prop="examineReason">
            <el-input type="textarea" v-model="form.examineReason" placeholder="请输入审核原因"
              :autosize="{ minRows: 5, maxRows: 55 }" style="max-Width:400px;"></el-input>
          </el-form-item>
          <div style="text-align: right;margin-bottom:10px;">
            <el-button type="warning" @click="handleExport">导 出</el-button>
            <el-button type="primary" @click="submitForm">确 定</el-button>
            <el-button @click="cancel">取 消</el-button>
          </div>
        </el-form>
        <el-table v-loading="loading" :data="itemList" border resizable height="70vh">
          <el-table-column type="index" width="80" label="序号"></el-table-column>
          <el-table-column label="检查项目" align="center" prop="checkItem" class-name="tableLi" />
          <el-table-column label="所属工序" align="center" prop="workSequenceName" class-name="tableLi" />
          <el-table-column label="检验类型" align="center" prop="checkTypeName" class-name="tableLi" />
          <el-table-column label="检查结果" align="center" prop="checkResult" width="240">
            <template slot-scope="scope">
              <div>
                <el-checkbox v-model="scope.row.checkResult" true-label="1" false-label="0"
                  @change="(value) => checkChange(value, scope.$index)"></el-checkbox>
                <!-- <el-radio-group v-model="scope.row.inspectionResult" @input="checkChange">
                  <el-radio :label="1" value="1">√</el-radio>
                  <el-radio :label="0" value="0">×</el-radio>
                </el-radio-group>-->
              </div>
            </template>
          </el-table-column>
        </el-table>
        <iqc-detail v-if="detailVisible" ref="detailOrUpdate"></iqc-detail>
      </div>
    </el-drawer>
  </div>
</template>

<script>
import {
  checkDetailList,
  checkExamine
} from "@/api/mes/pro/result";
import iqcDetail from "../../qc/iqc/iqc_detail.vue";
import moment from "moment";
export default {
  name: "receiptDetails",
  dicts: ["mes_workorder_status", "sys_fentry_status"],
  components: { iqcDetail },
  data() {
    return {
      // 是否显示弹出层
      showFlag: false,

      detailVisible: false,
      // 遮罩层
      loading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 生产补料详细信息表格数据
      detailList: [],
      // 弹出层标题
      title: "",

      //勾选的内容
      selectData: null,
      receiptId: null,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        materialSerial: null,
        productCode: null,
        productName: null,
        productSpec: null,
        measureName: null,
        itemAmount: null,
        receiptId: this.receiptId,
        suppyTime: null,
        workorderCode: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        auditResult: [
          { required: true, message: "请选择检验结果", trigger: "change" }
        ]
      },
      //审批人
      personList: [],
      //处于哪个环节
      activeStep: null,
      stepResult: null,
      itemList: []
    };
  },
  created() { },

  methods: {
    init(row) {
      console.log(row, "子组件的row");
      this.form = row;
      // this.FORM.auditResult = null
      //调接口需要的id
      this.stationCheckId = row.id;
      this.showFlag = true;
      this.getDetail();
    },
    getDetail() {
      this.loading = true;
      checkDetailList({ stationCheckId: this.stationCheckId }).then(response => {
        this.itemList = response.rows || {};
        this.loading = false;
      });
    },

    // 取消按钮
    cancel() {
      this.showFlag = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        materialSerial: null,
        productCode: null,
        productName: null,
        productSpec: null,
        measureName: null,
        itemAmount: null,
        receiptId: null,
        suppyTime: null,
        createTime: null,
        createBy: null,
        auditReason: null,
        auditResult: null
      };
      this.personList = [];
      //处于哪个环节
      this.activeStep = null;
      this.stepResult = null;
      this.warehouseList = [];
      this.resetForm("formCheck");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    viewReport(isEdit, row) {
      this.detailVisible = true;
      this.$nextTick(() => {
        this.$refs.detailOrUpdate.init(isEdit, row);
      });
    },
    //导出按钮操作
    handleExport() {
      this.download(
        "mes/station/stationCheckDetail/export",
        {
          "stationCheckId": this.stationCheckId
        },
        `工位自检明细记录_${moment(new Date()).format('yyyyMMDDHHmmss')}.xlsx`
      );
    },
    submitForm() {
      this.$refs["formCheck"].validate(valid => {
        if (valid) {
          console.log(this.form, "===========form=============");
          // let flowType = this.form.workflowStatus =='0' ? 'sqesh' : this.form.workflowStatus =='1' ? "pzbsh" : null
          // console.log(flowType,"=================flowtype===========");
          // this.form.flowType = flowType
          checkExamine(this.form).then(response => {
            this.$modal.msgSuccess("审核成功");
            this.reset()
            this.showFlag = false;
            this.$emit('parentList')
            // this.getList();
          });
        }
      });
    }
  }
};
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
.titleDiv {
  font-weight: 700 !important;
  font-size: 20px;
}

.tabsDiv {
  padding: 20px;
  padding-top: 0;
}

.tabsDiv ::v-deep .el-tabs--card>.el-tabs__header .el-tabs__item {
  font-weight: 700;
  font-size: 18px;
}

.drawerFooter {
  text-align: right;
  padding: 20px;
}

.bg-purple {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  line-height: 30px;
  // span:nth-child(1) {
  //   display: inline-block;
  //   width: 160px;
  //   white-space: nowrap;
  //   line-height: 30px;
  // }
}

.dialog-footer {
  padding-top: 20px;
  text-align: center;
}

.app-container ::v-deep .el-drawer__header {
  padding-top: 10px !important;
  padding-bottom: 5px !important;
  margin-bottom: 10px !important;
}
</style>